package java67_adv9;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;

public class ServerTest {

	public static void main(String[] args) throws IOException {
		// 监听在9999端口
		ServerSocket st = new ServerSocket(9999);
		System.out.println("服务器启动成功");
		while (true) {
			Socket s = st.accept();
			System.out.println("客户端的信息:" + s.getInetAddress() + ",端口:" + s.getPort());
			try {
				InputStream in = s.getInputStream();
				OutputStream out = s.getOutputStream();
				int i = 0;
				while ((i = in.read()) != -1) {
					System.out.print((char) i);
				}
			} catch (Exception e) {
				System.out.println("流出问题了,关闭");
				e.printStackTrace();
			} finally {
				try {
					if (s != null)
						s.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

}
